//
//  ToJsonData.swift
//  Exchange
//
//  Created by rui on 2018/6/11.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

protocol ToJsonData {
    var jsonData: Data? {get}
    var jsonString: String? {get}
}

extension ToJsonData {
    var jsonData: Data? {
        guard let data = try? JSONSerialization.data(withJSONObject: self, options: .prettyPrinted) else {
            return nil
        }
        return data
    }
    var jsonString: String? {
        guard let data = try? JSONSerialization.data(withJSONObject: self, options: .prettyPrinted) else {
            return nil
        }
        let json = String(data: data, encoding: .utf8)
        return json
    }
}
